/*
 * HTMLLexer.h
 *
 *  Created on: 2010-5-2
 *      Author: Guobc
 */

#ifndef HTMLLEXER_H_
#define HTMLLEXER_H_

#include <fstream>
#include <string>
#include "Lexer.h"
#include "Token.h"

namespace HA {

class HTMLLexer: public HA::Lexer {
public:

	/**
	 * construct method
	 * @param name HTML file name
	 * */
	HTMLLexer(string name);

	/*
	 * Return next token.
	 *
	 * @return A token.
	 * */
	inline Token* nextToken() throw (ParserException) {
		return fetchToken();
	}

	/**
	 * Set document to lexer
	 * @param document.
	 */
	inline void setDocument(ASTDom* document) {
		mDocument = document;
	}

	/**
	 * Get document of this lexer.
	 * @return
	 */
	inline ASTDom* getDocument() {
		return mDocument;
	}

	/**
	 * Open this lexer input stream.
	 * @return True if success, false otherwise.
	 */
	inline bool open() {
		fin.open(fName.c_str());
		return fin.is_open();
	}

	/**
	 * Test whether input stream is open.
	 * @return True is open, false otherwise.
	 */
	inline bool isOpen() {
		return fin.is_open();
	}

	/**
	 * close this lexer input stream.
	 * @return True if success, false otherwise.
	 */
	inline void close() {
		fin.close();
	}

	/**
	 * Get the position from the input character stream.
	 * @return
	 */
	int getPosition();

	/**
	 * Get the line number from the input character stream.
	 * return
	 */
	inline int getLineNumber(){
		return mLine;
	}

protected:

	/**
	 * Fetch a token from character stream.
	 * @return A token.
	 */
	Token* fetchToken() throw (ParserException);

private:

	Token* newToken(string line, int type);

private:
	int mLine;

};

}

#endif /* HTMLLEXER_H_ */
